import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
import { patientFormData } from './defaultData'
// ===================================================================== global declare
const { globalConfig, $fn, $http, $Lazy } = window
const { COVIDUrl } = globalConfig
// ===================================================================== 
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		formData: patientFormData.call(this)
	}
	submit = {}
	componentDidMount(){
		this.getSelect()
	}
	open = (uuid)=> {
		this.submit.uuid = uuid
		this.modal.open({formRef: this.formRef})
		const { formData } = this.state
		$fn.disabledRows(this.state.formData, ['specCode', 'hospId' ], true)
		$http.submit(null,COVIDUrl+'/caseinfo/getrow',{ param:{uuid}, loading:false }).then(data=>{
			this.formRef.reset()
			for(let key in data){
				if($fn.isString(data[key])){
					data[key]=data[key].replace(/(^\s*)|(\s*$)/g,"")
				}
			}
			if(+data.checkType === 1){
				$fn.getRow(formData, 'cardNo').required = false
			}else{
				$fn.getRow(formData, 'cardNo').required = true
			}
			this.formRef.setValue(data)
			this.setState({ formData })
		})
	}

	// 获取下拉数据
	getSelect = () => {
		const { formData } = this.state
		
		$cache.then( async f => {
			// 医院名称
			$fn.setRow( formData, 'hospId', await f.getCache({ api:COVIDUrl+'Hospital/query',param:{page:1,page_num:10000,status:1} }) )
	
			this.setState({ formData })
		})
	}
	
	render(){
		return FormModal.call(this,{ title:'编辑', labelWidth:'s6', api:COVIDUrl+'caseinfo/update', width:900,enter:false, })
	}
}

export default Index